package me.shurufa.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.Bind;
import me.shurufa.R;
import me.shurufa.utils.Constants;

/**
 * 摘书后添加笔记页面
 *
 * @FileName: me.shurufa.activities.WriteNoteActivity.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-02-14 11:11
 */
public class WriteNoteActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.left_text)
    TextView leftText;
    @Bind(R.id.right_image)
    ImageView rightImage;
    @Bind(R.id.right_text)
    TextView rightText;
    @Bind(R.id.toolbar_divider)
    View toolbarDivider;
    @Bind(R.id.edit_note)
    EditText editNote;
    private String noteExtra;
    private InputMethodManager imm;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_write_note;
        super.onCreate(savedInstanceState);
        uiInit();
    }

    private void uiInit() {
        titleTextView.setText(getString(R.string.mark_down));
        rightText.setVisibility(View.VISIBLE);
        rightText.setText(getString(R.string.complete));
        rightText.setOnClickListener(this);
        noteExtra = getIntent().getStringExtra(Constants.ARG_DIGEST_NOTE);
        if (!TextUtils.isEmpty(noteExtra));
        editNote.setText(noteExtra);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.right_text:
                imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editNote.getWindowToken(), 0);
                String trim = editNote.getText().toString().trim();
                Intent intent = new Intent();
                intent.putExtra(Constants.ARG_DIGEST_NOTE,trim);
                setResult(RESULT_OK,intent);
                finish();
                break;
        }
    }
}
